/**
 * 
 */
package com.thor.palmmall.rest.product.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.product.AProductChange;
import com.thor.palmmall.spi.product.SProductChange4Create;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SProductChange4CreateConverter
    implements Converter<AProductChange, SProductChange4Create> {

  public static SProductChange4CreateConverter getInstance() {
    if (instance == null)
      instance = new SProductChange4CreateConverter();
    return instance;
  }

  private static SProductChange4CreateConverter instance;

  private SProductChange4CreateConverter() {
  }

  @Override
  public SProductChange4Create convert(AProductChange source) {
    if (source == null) {
      return null;
    }
    SProductChange4Create target = new SProductChange4Create();
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setContract(UCN.newInstance(source.getContract()));
    target.setPrintPriceTag(source.isPrintPriceTag());
    target.setPrintQty(source.getPrintQty());
    target.setRemark(source.getRemark());
    target.setProducts(
        ConverterUtil.convert(source.getProducts(), SProductChangeLineConverter.getInstance()));

    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    return target;
  }

}
